<?php
include 'sysco.function.php';

$con = mysql_connect($HOST, $USER, $PASS);
mysql_select_db($DB);

$fp = fopen('reports/sysco_menuitems_'.$MERCHANT.'.csv', 'w');
$tmp = array('Cat Name', 'Cat Description', 'Item Name', 'Item Description');

$items = getMenuItems($MERCHANT);

$tmp = array('Code', 'Name', 'Description');
fputcsv($fp, $tmp);
      
foreach ($items as $K => $item) {
  foreach ($item as $kk => $t1) {
    if ($kk == 'MAIN_CAT') {
      $tmp = array($t1.' (Full Menu)');
      fputcsv($fp, $tmp);
      continue;
    }
    
    $name = $t1['NAME'];
    $t1['CODE'] = (strlen($t1['CODE']) > 20) ? rand(100,900) : $t1['CODE'];
    if (!empty($t1['NAME'])) {
      $tmp = array($name, $t1['CODE'].':'.$t1['NAME'], $t1['DESCR']);
      fputcsv($fp, $tmp);
    }
  }
}

// P.CODE, P.NAME, P.DESCRIPTION as PDESC, C.NAME as CNAME, C.DESCRIPTION as CDESC, P.ID as PID, C.PARENTID, C.ID as CAT_ID 
fclose($fp);
?>